<!--
	///////////////////////////////////////////
	开 发 者：sdrzlyl
	开发时间：2021年01月12日
	修改时间：2021年09月29日
	功能介绍：此API为快捷认证API，请在使用前申请并填写AppId！
	///////////////////////////////////////////
-->
<?php 
error_reporting(E_ALL^E_NOTICE);
require_once './config/config.php';
require '../config/config.php';
session_start();
?>
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>快捷认证</title>
</head>
<body>
<!--请注意，核心代码区域禁止修改！-->
<!--核心代码区域开始-->
<?php 
if (empty($AppId) or empty($AuthAPI) or empty($API)) {
    echo "请配置config/config.php文件！";
} else {
    $Acc=$_GET['Acc'];
	$Token=$_GET['Key'];
	if(!empty($Acc) && !empty($Token)){
		$ch = curl_init();
		$str =$API."?Acc=".$Acc."&Key=".$Token;
		curl_setopt($ch, CURLOPT_URL, $str);
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
		$output =curl_exec($ch);
		$output = mb_convert_encoding($output, "GBK", "UTF-8");
		$output=substr($output,1);
		//var_dump( $output );
		if($output=="666666"){
		    if($_SESSION['user']!=""){
				$userRs=mysqli_fetch_array(mysqli_query($con,"select * from user where user='".$_SESSION['user']."'"));
				$rs=mysqli_fetch_array(mysqli_query($con,"select * from link where hypassport = '" . $Acc . "'"));
                if(empty($rs['uid'])){
                    mysqli_query($con,"INSERT INTO `link` (`link_id`, `uid`, `hypassport`) VALUES (NULL, '".$userRs['uid']."', '".$Acc."')");
		        	echo "<script>alert('绑定成功！');location='../my.php';</script>";
                }else{
					echo "<script>alert('请勿多次绑定！');location='../my.php';</script>";
				}
		        
		    }else{
		        $rs=mysqli_fetch_array(mysqli_query($con,"select * from link where hypassport = '" . $Acc . "'"));
                if(empty($rs['uid'])){
                    echo "<script>alert('此账号未绑定到该网站！');location='../login.php';</script>";
                }else{
                    $result = mysqli_query($con,"select * from user where uid = '".$rs['uid']."'");
                    $rs=mysqli_fetch_array($result);
                    $num = mysqli_num_rows($result);
                    if($num){
                        if($rs['state']!="1"){
                            echo "<script>alert('该账号状态异常，暂时无法登录！');location='../login.php';</script>";
                        }else{
            			    $_SESSION['user']=$rs['user'];
                	    	if($_SESSION['url']==""){
        		    	        echo "<script>alert('登录成功！');location='../index.php';</script>";
        		    	    }else{
        		    	        echo "<script>alert('登录成功！');location='".$_SESSION['url']."';</script>";
        		    	    }
                        }
                    }
                    
                }
		    }
            
			
			//这里请编写认证成功后的操作！
		}else{
			echo "<script>alert('认证失败！');location='../login.php';</script>";
			//echo "<script>alert('认证失败！');location='index.php';</script>";
			//这里请编写认证失败的操作！
		}
	}
}
?>
<!--核心代码区域结束-->
</body>
</html>